package com.example.websocket.mapper;

import com.example.websocket.pojo.CommentPo;
import com.example.websocket.pojo.LikePo;
import com.example.websocket.pojo.Pyq;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ author 韩
 * time: 2024/3/8 11:51
 */
@Mapper
public interface PyqMapper {

    @Insert("insert into `like` (pyq_id,username) values (#{pyqId},#{username})")
    boolean addLike(int pyqId, String username);

    @Delete("delete from `like` where pyq_id = #{pyqId} AND username = #{username}")
    boolean deleteLike(int pyqId,String username);

    @Select("select * from pyq order by id DESC")
    List<Pyq> getPyqList();

    @Select("select `username` from `like` where pyq_id = #{id}")
    List<LikePo> getLikeList(int id);

    @Select("select username,content from `comment` where pyq_id = #{id}")
    List<CommentPo> getCommentList(Integer id);

    @Insert("insert into `comment` (pyq_id,username,content) values (#{pyqId},#{username},#{content})")
    boolean addComment(Integer pyqId, String username, String content);

    @Insert("insert into `pyq` VALUES (null,#{username}, #{content}, NOW())")
    Boolean publishPyq(String username, String content);
}
